package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.linlinjava.litemall.db.mybatis.JsonIntegerArrayTypeHandler;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Lumiere支付会员
 *
 * @author yliyun
 * @date 2022/09/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("lumiere_pay_member")
public class LumierePayMember implements Serializable {
    /**
     * 被删除
     */
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    /**
     * 不删除
     */
    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    /**
     * id
     */
    @TableId
    private Integer id;

    /**
     * 名字
     */
    private String name;

    /**
     * 照片url
     */
    private String picUrl;

    /**
     * 使用范围
     */
    private Byte useRange;

    /**
     * 商店id
     */
    @TableField(typeHandler = JsonIntegerArrayTypeHandler.class)
    private Integer[] shopIds;

    /**
     * 天到期
     */
    private Integer expiredDays;

    /**
     * 钱
     */
    private BigDecimal money;

    /**
     * 点
     */
    private BigDecimal point;

    /**
     * 是支持reneval
     */
    private Boolean isSupportReneval;

    /**
     * reneval钱
     */
    private BigDecimal renevalMoney;

    /**
     * reneval点
     */
    private BigDecimal renevalPoint;

    /**
     * 点比
     */
    private Integer pointRatio;

    /**
     * 添加时间
     */
    private LocalDateTime addTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 删除
     */
    private Boolean deleted;

    /**
     * 状态
     */
    private Byte status;

    /**
     * 购买时间
     */
    private Integer buyTimes;

    /**
     * dicount每
     */
    private BigDecimal dicountPer;

    /**
     * 礼品卡id
     */
    private Integer[] giftCardIds;

    /**
     * 付费说明
     */
    private String paymentInstructions;

    /**
     * 优惠叠加 ：0 No| 1 Yes
     */
    private Integer isOverlay;

    /**
     * 有效期 开始时间
     */
    private LocalDateTime startTime;

    /**
     * 有效期 结束时间
     */
    private LocalDateTime endTime;



    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        name("name", "name", "VARCHAR", true),
        picUrl("pic_url", "picUrl", "VARCHAR", false),
        useRange("use_range", "useRange", "TINYINT", false),
        shopIds("shop_ids", "shopIds", "VARCHAR", false),
        expiredDays("expired_days", "expiredDays", "INTEGER", false),
        money("money", "money", "DECIMAL", false),
        point("point", "point", "DECIMAL", false),
        isSupportReneval("is_support_reneval", "isSupportReneval", "BIT", false),
        renevalMoney("reneval_money", "renevalMoney", "DECIMAL", false),
        renevalPoint("reneval_point", "renevalPoint", "DECIMAL", false),
        pointRatio("point_ratio", "pointRatio", "INTEGER", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false),
        status("status", "status", "TINYINT", true),
        buyTimes("buy_times", "buyTimes", "INTEGER", false),
        dicountPer("dicount_per", "dicountPer", "DECIMAL", false),
        giftCardIds("gift_card_ids", "giftCardIds", "VARCHAR", false),
        paymentInstructions("payment_instructions", "paymentInstructions", "VARCHAR", false);
        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}
